const Mock = require('mockjs')

const user = require('./modules/user')
const table = require('./modules/table')
const article = require('./modules/article')
const search = require('./modules/search')
const role = require('./modules/role')


const mocks = [
  ...user,
  ...table,
  ...article,
  ...search,
  ...role,
]

module.exports = (req, res, next) => {
  let url = req.url
  if (url.indexOf('?') > 0) {
    url = url.substring(0, url.indexOf('?'))
  }
  console.log("url=", url)
  for (const i of mocks) {
    if (url === i.url) {
      response = i.response(req, res, next);
      if (response == null) {
      } else {
        res.jsonp(
          response
        );
        return;
      }
    }
  }
  // console.log("server.use=",req.url)
  // if (req._parsedOriginalUrl) {
  //   console.log("server.use=",req._parsedOriginalUrl.pathnam)
  // }
  // let url = req.url
  // if (url.indexOf('?') > 0) {
  //   url = url.substring(0, url.indexOf('?'))
  // }
  // console.log("url=",url)
  // //res.header('X-Hello', 'World')
  // console.log(req.url, '=', req.query, req.body);//抓取提交过来的query和body
  // console.log('res=', res.query, res.body, res.locals.data);//抓取提交过来的query和body
  next()
}